package gappengko;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/** JSONP interface for getting a map based on its key value (Datastore key). */
public class GetServlet  extends HttpServlet {
  
  private static final long serialVersionUID = 1L;

  private HttpRequestHandler _handler = new HttpRequestHandler();

	/** gets the map corresponding to  {@code req.getParameter(Constants.KEY)} */
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws IOException {
		try { 
			String json = _handler.getJson(req);
			ContentNegotiationUtils.processRequest(req, res, json);
		} catch (Exception e) {
		  throw new RuntimeException(e);
		}
	}
	
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
	
	@Override
	public void doOptions(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		CrossDomainUtils.doOptions(req, res);
	}
}
